<?php
namespace app\shop\model;
use app\shop\model\SpecPriceModel;
use think\Model;

class GrabBuyModel extends Model
{
    protected $table = 'dp_grab_buy';
    protected $pk = 'id';
    protected $field = true;


    public static function getList()
    {
        return self::order('id desc')->paginate(10);

    }

    public static function getOne($id=0)
    {
        return self::where('id', $id)->find();

    }

    public static function store($data, $id=0)
    {
        if($id == 0){
            return self::insert($data);
        }else{

            return self::where('id', $id)->update($data);
        }
    }

    public static function del($ids=0)
    {
        //将抢购的所有规格商品进行还原
        $goods_ids = self::where('id',$ids)->value('goods_ids');
        SpecPriceModel::whereIn('goods_id',$goods_ids)->update(['grab_price'=>0,'grabstore_num'=>0]);
        GoodsModel::whereIn('id',$goods_ids)->update(['grab_price'=>0,'grabstore_num'=>0]);
        return self::where('id',$ids)->delete();
    }


}